<template>
    <el-dialog
            title="回复反馈"
            :close-on-click-modal="false"
            :visible.sync="showModal"
            @close="cancel"
            width="800px"
    >
        <div class="roleWarps" v-loading="loading" :element-loading-text="loadingText">
            <el-form
                    ref="formDataRefs"
                    :model="feedbackForm"
            >
                <el-form-item label="回复内容">
                    <el-input type="textarea" v-model="feedbackForm.replyContent"></el-input>
                </el-form-item>
            </el-form>
        </div>
        <div slot="footer" class="footer_dialog">
            <el-button size="small" @click="cancel">取消</el-button>
            <el-button size="small" @click="saveInfo" type="primary" :loading="loading">确定</el-button>
        </div>
    </el-dialog>
</template>

<script>
    import { _replyContent } from '_api'
    import vueState from '@lib/vuexState'
    import http from "../../../http/config";

    export default {
        name: "feedbackModal",
        mixins: [vueState],
        data(){
            return{
                showModal: false,
                loading: false,
                loadingText: '保存中...',
                feedbackForm:{
                    feedbackId:'',
                    replyContent:''
                }
            }
        },
        methods:{
            saveInfo(){
                this.$refs.formDataRefs.validate(async (valid) => {
                    if (valid) {
                        let data = JSON.parse(JSON.stringify(this.feedbackForm))
                        this.loading = true
                        this.loadingText = '保存中...'
                        let res = (await _replyContent(data))
                        if (res && res.code == '0') {
                            this.$message.success(res.msg)
                            this.$emit('refresh')
                            this.cancel()
                        }
                    }
                })
            },
            cancel() {
                this.showModal = false
                this.loading = false
            },
            getInfo(){
                this.loading = true
                this.loadingText = '查询中...'
                http.post('/cms/auth/user/feedback/getFeedback',this.feedbackId).then(res=>{
                    this.feedbackForm.feedbackId = this.feedbackId
                    this.loading = false
                })
            }
        },
        watch: {
            showModal: {
                handler(val) {
                    if (val) this.getInfo()
                },
                immediate: true
            }
        }
        ,props: {
            feedbackId: {
                type: String,
                default: ''
            }
        },
    }
</script>

<style scoped>

</style>
